package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.entity.IsolationInfo;
import com.ruoyi.system.mapper.IsolationInfoMapper;
import com.ruoyi.system.service.IsolationInfoService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author ruochen
* @description 针对表【isolation_info(隔离点信息)】的数据库操作Service实现
* @createDate 2023-11-18 11:59:55
*/
@Service
public class IsolationInfoServiceImpl extends ServiceImpl<IsolationInfoMapper, IsolationInfo>
    implements IsolationInfoService {


    @Override
    public List<IsolationInfo> getIsolationInfoList() {

        LambdaQueryWrapper<IsolationInfo> isolationInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        isolationInfoLambdaQueryWrapper.select(IsolationInfo::getIsolationId,IsolationInfo::getIsolationName);
        List<IsolationInfo> isolationInfos = this.list(isolationInfoLambdaQueryWrapper);
        if (isolationInfos.size() == 0){
            throw new RuntimeException("隔离点信息为空");
        }
        return isolationInfos;
    }

    @Override
    public IsolationInfo getIsolationInfoById(Long id) {
        IsolationInfo isolationInfo = this.getById(id);
        if (isolationInfo == null){
            throw new RuntimeException("隔离点信息为空");
        }
        return isolationInfo;
    }

    @Override
    public List<IsolationInfo> getAllIsolationInfoList(IsolationInfo isolationInfo) {

        LambdaQueryWrapper<IsolationInfo> isolationInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        // 按照创建时间倒序排列
        isolationInfoLambdaQueryWrapper.orderByDesc(IsolationInfo::getCreateTime);
        if (isolationInfo.getIsolationName()!= null){
            isolationInfoLambdaQueryWrapper.like(IsolationInfo::getIsolationName,isolationInfo.getIsolationName());
        }
        if (isolationInfo.getFacilityType()!= null){
            isolationInfoLambdaQueryWrapper.like(IsolationInfo::getFacilityType,isolationInfo.getFacilityType());
        }
        if(isolationInfo.getIsolationLongitude() != null){
            isolationInfoLambdaQueryWrapper.eq(IsolationInfo::getIsolationLongitude,isolationInfo.getIsolationLongitude());
        }
        if(isolationInfo.getIsolatedLatitude() != null){
            isolationInfoLambdaQueryWrapper.eq(IsolationInfo::getIsolatedLatitude,isolationInfo.getIsolatedLatitude());
        }
        if(isolationInfo.getIsolationAddress() != null){
            isolationInfoLambdaQueryWrapper.like(IsolationInfo::getIsolationAddress,isolationInfo.getIsolationAddress());
        }
        if (isolationInfo.getStatus() != null){
            isolationInfoLambdaQueryWrapper.eq(IsolationInfo::getStatus,isolationInfo.getStatus());
        }
        List<IsolationInfo> isolationInfos = this.list(isolationInfoLambdaQueryWrapper);

        return isolationInfos;
    }

    @Override
    public Boolean deleteIsolationInfoById(Long id) {
        boolean b = this.removeById(id);
        if(!b){
            throw new RuntimeException("删除隔离点信息失败");
        }
        return b;
    }

    @Override
    public Boolean addIsolationInfo(IsolationInfo isolationInfo) {
        boolean b = this.save(isolationInfo);
        if(!b){
            throw new RuntimeException("添加隔离点信息失败");
        }
        return b;
    }


    @Override
    public Boolean updateIsolationInfo(IsolationInfo isolationInfo) {
        boolean b = this.updateById(isolationInfo);
        if(!b){
            throw new RuntimeException("更新隔离点信息失败");
        }
        return b;
    }
}




